package com.itcast.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcast.reggie.pojo.Orders;
import com.itcast.reggie.pojo.R;
import com.itcast.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
//订单
@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersControllers{
    @Autowired
    private OrdersService ordersService;

    //订单查询(管理端)
    @GetMapping("/page")
    public R<Page> GetByConditions(int page, int pageSize, String number,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime beginTime ,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime){
        Page<Orders> ordersDto=ordersService.getPages(page,pageSize,number,beginTime,endTime);
        return R.success(ordersDto);
    }


    //添加订单
    @PostMapping("/submit")
    public R Add(@RequestBody Orders order){
        ordersService.submit(order);
        return R.success("添加成功");
    }

    //查询订单(手机端)
    @GetMapping("/userPage")
    public R<Page> getPages(int page,int pageSize,String number,
                            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime beginTime ,
                            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime){
        Page<Orders> ordersDto=ordersService.getPages(page,pageSize, number, beginTime, endTime);
        return R.success(ordersDto);
    }

    @PutMapping
    public R updateStatus(@RequestBody Orders orders){
        ordersService.updateById(orders);
        return R.success("修改成功");
    }

}
